package com.bq.gametrade.adapter;

import android.content.Context;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bq.gametrade.R;
import com.bq.gametrade.bean.TransferContactsDetails;

import java.util.ArrayList;

/**
 * Created by Feel on 2016/12/27.
 */

public class TransferContactsListAdapter extends BaseAdapter {

    private ArrayList<TransferContactsDetails> mDatas;
    private Context context;

    public TransferContactsListAdapter(Context context, ArrayList<TransferContactsDetails> list ) {
        this.mDatas = list;
        this.context = context;

    }

    public void setData(ArrayList<TransferContactsDetails> list) {
        this.mDatas = list;

    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int position) {
        return mDatas.get(position);
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view ==null){
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.listview_transfercontacts_item,null);
            viewHolder.tvFriendNickName = (TextView) view.findViewById(R.id.tv_friendNickName);
            viewHolder.tvFriendPhoneNumber = (TextView) view.findViewById(R.id.tv_friendPhoneNumber);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder)view.getTag();
        }
        TransferContactsDetails details = mDatas.get(position);
        if(details.userName.equals("")){
            viewHolder.tvFriendNickName.setText(details.bqAccount);
            viewHolder.tvFriendNickName.setTextColor(context.getResources().getColor(R.color.color666666));
        }else {
            viewHolder.tvFriendNickName.setText(new String(Base64.decode(details.userName.getBytes(), 0, details.userName.length(), Base64.DEFAULT)));
        }
        viewHolder.tvFriendPhoneNumber.setText(details.userId);

        return view;
    }

    class ViewHolder{
        TextView tvFriendNickName;
        TextView tvFriendPhoneNumber;

    }
}
